/*
 * Copyright (c) 2014-2020 杭州派迩信息技术有限公司 All Rights Reserved.
 * ProjectName: pi-flowable-project
 * ModuleName: pi-actuator-service
 * FileName: PiActuatorProjectServiceImpl.java
 * Author: kai.li
 * Date: 2021/08/31 18:16:31
 * Version: 1.0
 * LastModified: 2021/08/31 18:16:31
 */

package com.pisolution.actuator.service.service.impl;

import com.pisolution.actuator.service.exception.ActuatorServiceException;
import com.pisolution.actuator.service.mapper.PiActuatorProjectMapper;
import com.pisolution.actuator.service.model.PiActuatorProject;
import com.pisolution.actuator.service.service.PiActuatorProjectService;
import com.pisolution.actuator.service.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.Instant;
import java.util.List;

/**
 * @className: PiActuatorProjectServiceImpl
 * @description: 服务实现类
 * @author: kai.li
 * @date: 2021/08/31 18:16:31
 * @since: 1.0
 */
@Service
public class PiActuatorProjectServiceImpl implements PiActuatorProjectService {

    @Autowired
    private PiActuatorProjectMapper piActuatorProjectMapper;

    @Override
    public Boolean addProject(PiActuatorProject piActuatorProject) {
        List<PiActuatorProject> projects = piActuatorProjectMapper.selectByProjectName(piActuatorProject.getProjectName());
        if(!CollectionUtils.isEmpty(projects)){
            throw new ActuatorServiceException("工程名已存在！");
        }
        piActuatorProject.setCreateTime(Instant.now());
        piActuatorProject.setId(IdUtil.getInstance().getId());
        piActuatorProject.setCreateUserId(-1L);
        Integer addNumber = piActuatorProjectMapper.insert(piActuatorProject);
        if(addNumber > 0){
            return true;
        }else{
            return false;
        }
    }
}
